package com.hucheng.seckill.entity;

import com.hucheng.seckill.dto.SeckillOrderDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 持久层参数
 **/
@Data
public class SeckillOrderDO {
    private Integer seckillOrderId;
    private Integer userId;
    private Integer orderId;
    private Integer goodsId;
    private Timestamp seckillOrderDateCreated;
    private Timestamp seckillOrderDateUpdated;

    public static SeckillOrderDO buildSeckillGoodsDO(final SeckillOrderDTO seckillOrderDTO) {
        if (seckillOrderDTO != null) {
            SeckillOrderDO seckillOrderDO = new SeckillOrderDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(seckillOrderDTO.getSeckillOrderId() + "")) {
                seckillOrderDO.setSeckillOrderId(seckillOrderDTO.getSeckillOrderId());
                seckillOrderDO.setSeckillOrderDateCreated(currentTime);
            } else {
                seckillOrderDO.setSeckillOrderDateUpdated(currentTime);
            }
            seckillOrderDO.setUserId(seckillOrderDTO.getUserId());
            seckillOrderDO.setOrderId(seckillOrderDTO.getOrderId());
            seckillOrderDO.setGoodsId(seckillOrderDTO.getGoodsId());
            return seckillOrderDO;
        }
        return null;
    }
}
